using Microsoft.EntityFrameworkCore;

namespace EFCoreDbSetDemo;

public class ApplicationDbContext : DbContext
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
    {

    }

    public DbSet<Order> Orders { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Order>().ToTable("Orders").HasKey(o => o.Id);
        modelBuilder.Entity<Order>().Property(t => t.Id).ValueGeneratedOnAdd();
        modelBuilder.Entity<Order>().HasMany(o => o.OrderItems);

        modelBuilder.Entity<OrderItem>().ToTable("OrderItems").HasKey(o => o.Id);
        modelBuilder.Entity<OrderItem>().Property(t => t.Id).ValueGeneratedOnAdd();

        base.OnModelCreating(modelBuilder);
    }
}